/**
 * 药品库
 */
Lib = cc.Sprite.extend({
	libArr: [],
	openFlag:false,
	doing:false,
	rm : 5,
	ctor:function(p){
		this._super("#lib_back.png");
		p.addChild(this,30);
		this.setTag(TAG_LIB);
		this.init();
	},
	init:function(){
		this.libArr = [];
		this.openFlag = false;
		this.setPosition(gg.width + this.width * 0.5 + 9,550);

		var drop = new LibButton(this, 10, TAG_LIB_DROP,"#bottle1.png", this.callback);
		drop.setPosition(30, this.height * 0.5);
		//this.addlabel(drop,"试剂瓶");
		
		
		var kettle = new LibButton(this, 10, TAG_LIB_KETTLE,"#kettle.png", this.callback);
		kettle.right(drop, this.rm);

		var cyl1 = new LibButton(this, 10, TAG_LIB_CYLINDER1,"#cylinder.png", this.callback);
		cyl1.right(kettle, this.rm);

		var beaker = new LibButton(this, 10, TAG_LIB_BEAKER,"#beaker.png", this.callback);
		beaker.right(cyl1, this.rm);
		
		var cyl = new LibButton(this, 10, TAG_LIB_CYLINDER,"#cylinder.png", this.callback);
		cyl.right(beaker, this.rm);
		//this.addlabel(cyl,"量筒");
		
		
		//this.addlabel(beaker,"烧杯");
		
		var rod =  new LibButton(this, 10, TAG_LIB_ROD,"#rod1.png", this.callback);
		rod.right(cyl, this.rm);
	//	this.addlabel(rod,"玻璃棒");
		
	
	
		
		var volumetric = new LibButton(this, 10, TAG_LIB_VOLUMETRIC,"#volumetric.png", this.callback);
		volumetric.right(rod, this.rm);
		//this.addlabel(volumetric,"容量瓶");
//
//		var burette = new LibButton(this, 10, TAG_LIB_BURETTE,"#burette.png", this.callback);
//		burette.right(volumetric, this.rm);
		

	},
	addlabel:function(obj,str){
		var label = new cc.LabelTTF(str,gg.fontName,"20");
		label.setColor(cc.color(0,0,0));
		label.setPosition(cc.p(0,-30));
		obj.addChild(label);
		
	},
	
	moveLib:function(tag,width){
		width = 75;
		var begin = false;
		for(var i in this.libArr){
			var libTag = this.libArr[i];
			if(tag == libTag){
				begin = true;
			}
			if(begin){
				var lib = this.getChildByTag(libTag);
				if(lib != null){
					lib.runAction(cc.moveBy(0.5,cc.p(-width, 0)));
				}
			}
		}
	},
	callback:function(p){
		var pos = this.getPosition(); 
		var action = gg.flow.flow.action;
		switch(p.getTag()){
		    case TAG_LIB_DROP:
			    ll.run.loadDrop(pos);
			    break;
			case TAG_LIB_CYLINDER:
				ll.run.loadCyl(pos);
				break;
			case TAG_LIB_CYLINDER1:
				ll.run.loadCyl1(pos);
				break;
			case TAG_LIB_BEAKER:
				ll.run.loadBeaker(pos);	
				break;
			case TAG_LIB_ROD:
				ll.run.loadRod(pos);
				break;
			case TAG_LIB_KETTLE:
				ll.run.loadKettle(pos);
				break;
			case TAG_LIB_GESUAN:
				ll.run.loadGesuan(pos);
				break;
			case TAG_LIB_YIYE:
				ll.run.loadYiye(pos);
				break;
			case TAG_LIB_XIERQIU:
				ll.run.loadXierqiu(pos);
				break;
			case TAG_LIB_WATER:
				ll.run.loadWater(pos);
				break;
			case TAG_LIB_XISHUIZHI:
				ll.run.loadXishuizhi(pos)
				break;			
			case TAG_LIB_SBEAKER:
				ll.run.loadSbeaker(pos);	
				break;
			case TAG_LIB_BEAKERFLASK:
				ll.run.loadBeakerflask(pos);	
				break;	
			case TAG_LIB_JIANSHINODE:
				ll.run.loadJianshinode(pos);	
				break;	
			case TAG_LIB_IRON:
				ll.run.loadIron(pos);
				break;
			case TAG_LIB_VOLUMETRIC:
				ll.run.loadVolumetric(pos);
				break;
				
			case TAG_LIB_BURETTE:
				ll.run.loadBurette(pos);
				break;
			default:
				break;
		}
		if(action == ACTION_NONE){
			this.moveLib(p.getTag(), p.width * p.getScale());
			p.removeFromParent(true);
		}
	},
	isOpen:function(){
		return this.openFlag; 
	},
	open:function(){
		if(this.openFlag || this.doing){
			return;
		}
		this.doing = true;
		var move = cc.moveBy(0.4, cc.p(-this.width,0));
		var func = cc.callFunc(function(){
			this.openFlag = true;
			this.doing = false;
			var tag = gg.flow.flow.tag;
			 if(tag instanceof Array){
				 if(TAG_LIB_MIN < tag[1]){
					 // 显示箭头
					 gg.flow.location();
				 }
			 }
		}, this);
		var seq = cc.sequence(move,func);
		this.runAction(seq);
	},
	close:function(){
		if(!this.openFlag || this.doing){
			return;
		}
		this.doing = true;
		var move = cc.moveBy(0.4, cc.p(this.width,0));
		var func = cc.callFunc(function(){
			this.openFlag = false;
			this.doing = false;
			var tag = gg.flow.flow.tag;
			if(tag instanceof Array){
				if(TAG_LIB_MIN < tag[1]){
					// 隐藏箭头
					//ll.tip.arr.out();
					ll.tip.arr.pos(ll.tool.getChildByTag(TAG_BUTTON_LIB));
				}
			}
		}, this);
		var seq = cc.sequence(move,func);
		this.runAction(seq);
	}
});
TAG_LIB_MIN = 30000;

TAG_LIB_DROP = 30001;
TAG_LIB_CYLINDER = 30002;
TAG_LIB_CYLINDER1 = 300002;
TAG_LIB_BEAKER = 30003;
TAG_LIB_ROD = 30004;
TAG_LIB_KETTLE = 30005;
TAG_LIB_GESUAN = 30006;
TAG_LIB_YIYE = 30007;
TAG_LIB_XIERQIU = 30008;
TAG_LIB_WATER = 30009;
TAG_LIB_XISHUIZHI = 30010;
TAG_LIB_SBEAKER = 30011;
TAG_LIB_BEAKERFLASK = 30012;
TAG_LIB_IRON = 30013;
TAG_LIB_JIANSHINODE=30014;
//TAG_LIB_POT = 30014;
//TAG_LIB_PH = 30015;
//TAG_LIB_AIR = 30016;
//TAG_LIB_SPOON = 30017;
//TAG_LIB_PAPER2 = 30018;
TAG_LIB_MATCH = 30019;
TAG_LIB_VOLUMETRIC=30020;


libRelArr = [
             {tag:TAG_LIB_MIN, name:""},
             {tag:TAG_LIB_DROP, name:"试剂瓶"},
             {tag:TAG_LIB_CYLINDER, name:"小量筒"},
             {tag:TAG_LIB_BEAKER, name:"烧杯"},
             {tag:TAG_LIB_ROD, name:"玻璃棒"},
             {tag:TAG_LIB_KETTLE, name:"蒸馏水瓶"},
             {tag:TAG_LIB_CYLINDER1, name:"大量筒"},
             {tag:TAG_LIB_VOLUMETRIC, name:"容量瓶"}];
             //{tag:TAG_LIB_BURETTE, name:"胶头滴管"}, ];
//             {tag:TAG_LIB_GESUAN, name:"铬酸"},
//             {tag:TAG_LIB_YIYE, name:"移液管"},
//             {tag:TAG_LIB_XIERQIU, name:"洗耳球"},
//             {tag:TAG_LIB_WATER, name:"自来水瓶"},
//             {tag:TAG_LIB_XISHUIZHI, name:"吸水纸"},
//             {tag:TAG_LIB_SBEAKER, name:"小烧杯"},
//             {tag:TAG_LIB_BEAKERFLASK, name:"锥形瓶"},
//             {tag:TAG_LIB_JIANSHINODE, name:"碱式滴定管"},
//             {tag:TAG_LIB_IRON, name:"铁架台"}];
//             {tag:TAG_LIB_PH, name:"pH试纸"},
//             {tag:TAG_LIB_AIR, name:"空气压缩机"},
//             {tag:TAG_LIB_PAPER2, name:"滤纸"},
//             {tag:TAG_LIB_MATCH, name:"火柴盒"},
//             {tag:TAG_LIB_WIDE, name:"广口瓶"}
            
